#include"stu.h"
#include"../ModuleA/cou.h" 
#include "link.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
void selectcourse(void) { //学生选课
	struct student *s;
	struct course *p;
	int a,i,b,j;
start:
	;
	printf("请输入你的学号：");
	scanf("%d",&a);
	s=head2;
	while((s->stu_id)!=a && s->next!=NULL)
		s=s->next;
	if(s->stu_id!=a) {
		printf("您的信息不存在，请重新输入!\n");
		goto start;
	}
start2:
	;
	printf("请输入您要选修的课程编号: ");
	scanf("%d",&b);
	p=head1;
	while((p->cou_num)!=b && p->next!=NULL)
		p=p->next;
	if(p->cou_num!=b) {
		printf("您输入的课程不存在，请重新输入!\n");
		goto start2;
	}
	if((p->nelepeo) >= (p->melepeo)) {
		printf("此课程人数已满，请选择其他课程\n");
		goto start2;
	}
	for(i=0; ; i++) {
		if(s->nelenum[i]==0) {
			s->nelenum[i]=b;
			break;
		}
	}
	(p->nelepeo)++;
	(s->nelen)++;
	(s->scoresum)+= (p->score);
	for(j=0; j<20; j++) {
		s->nelename[i-1][j]=(p->cou_name[j]);
	}
	printf("选课成功！\n");
	FILE *fp1;
	time_t timep;
	struct tm *p1;
	time(&timep);
	p1=gmtime(&timep);
	fp1=fopen("log.log","a");
	fprintf(fp1,"[%d年%d月%d日 %d:%d:%d]\t添加了一条选课信息。\n",1900+p1->tm_year,1+p1->tm_mon,p1->tm_mday,8+p1->tm_hour,p1->tm_min,p1->tm_sec);
	fclose(fp1);
end:
	;
}

void show_all() { //浏览全部信息
	struct course *p;
	p=head1;
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	printf("课程编号\t课程名称\t课程性质\t授课学时\t学分\t课程已选人数\t课程人数上限\n");
	while(p!=NULL) {
		printf("%6d%14s%18s%12d%16d%12d%16d\n",p->cou_num,p->cou_name,p->cou_type,p->hour,p->score,p->nelepeo,p->melepeo);
		p=p->next;
	}
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
	struct student *q;
	q=head2;
	printf("学生学号\t学生姓名\t已选课程学分\n");
	while (q!=NULL) {
		printf("%6d%14s%14d\n",q->stu_id,q->stu_name,q->scoresum);
		q=q->next;
	}
	printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
}
